package com.todo.strategy.pipeline.application.handler.planRelation;

import com.alibaba.fastjson.JSONObject;
import com.todo.strategy.pipeline.application.entity.context.PlanRelationActionContext;
import com.todo.strategy.pipeline.common.enums.OperateActionEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * @author azhebuxing
 * @date 2025/3/1 19:00
 * @description
 */
@Slf4j
public abstract class AbstractPlanRelationOperateHandle {

    public Boolean operateHandle(PlanRelationActionContext context) {
        log.info("AbstractPlanRelationOperateHandle handle start PStrategyOperateActionContext: 【{}】", JSONObject.toJSONString(context));
        if (match(context)) {
            try {
                Boolean result = doActionHandle(context);
                log.info("AbstractPlanRelationOperateHandle handle end action:【{}】 result: 【{}】", getStrategyActionEnum(), result);
            } catch (Exception ex) {
                log.error("AbstractPlanRelationOperateHandle handle error action:【{}】 context: 【{}】", getStrategyActionEnum(), JSONObject.toJSONString(context), ex);
            }
        }
        return true;
    }

    protected abstract Boolean doActionHandle(PlanRelationActionContext context);

    protected abstract Boolean match(PlanRelationActionContext context);

    protected abstract OperateActionEnum getStrategyActionEnum();
}
